<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改会议信息')" />
    <th:block th:include="include :: datetimepicker-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-meeting-edit" th:object="${meeting}">
            <h4 class="form-header h4">会议信息信息</h4>
            <input name="id" th:field="*{id}" type="hidden">
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label is-required">会议名称：</label>
                    <div class="col-sm-8">
                        <input name="meetingName" th:field="*{meetingName}" class="form-control" type="text" required>
                    </div>
                </div>
            </div>
<!--            <div class="col-xs-12">-->
<!--                <div class="form-group">-->
<!--                    <label class="col-sm-3 control-label">主持人：</label>-->
<!--                    <div class="col-sm-8">-->
<!--                        <input name="host" th:field="*{host}" class="form-control" type="text">-->
<!--                    </div>-->
<!--                </div>-->
<!--            </div>-->
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label is-required">开始时间：</label>
                    <div class="col-sm-8">
                        <div class="input-group date">
                            <input name="startTime" th:value="${#dates.format(meeting.startTime, 'yyyy-MM-dd MM:mm')}" class="form-control" placeholder="yyyy-mm-dd HH:ii" type="text" required>
                            <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label is-required">结束时间：</label>
                    <div class="col-sm-8">
                        <div class="input-group date">
                            <input name="endTime" th:value="${#dates.format(meeting.endTime, 'yyyy-MM-dd MM:mm')}" class="form-control" placeholder="yyyy-mm-dd HH:ii" type="text" required>
                            <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">会议地点：</label>
                    <div class="col-sm-8">
                        <input name="meetingAddress" th:field="*{meetingAddress}" class="form-control" type="text">
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label is-required">会员人数：</label>
                    <div class="col-sm-8">
                        <input name="meetingPeople" th:field="*{meetingPeople}" class="form-control" type="number" required>
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">备注：</label>
                    <div class="col-sm-8">
                        <textarea name="remark" th:field="*{remark}" class="form-control" rows="8" ></textarea>
                    </div>
                </div>
            </div>
            <!--<h4 class="form-header h4">人员签到信息信息</h4>
            <div class="row">
                <div class="col-sm-12">
                    <button type="button" class="btn btn-white btn-sm" onclick="addRow()"><i class="fa fa-plus"> 增加</i></button>
                    <button type="button" class="btn btn-white btn-sm" onclick="sub.delRow()"><i class="fa fa-minus"> 删除</i></button>
                    <div class="col-sm-12 select-table table-striped">
                        <table id="bootstrap-table"></table>
                    </div>
                </div>
            </div>-->
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <script th:inline="javascript">
        var prefix = ctx + "business/meeting";
        $("#form-meeting-edit").validate({
            focusCleanup: true,
            rules: {
                endTime: {
                    required: true,
                    compareTime: "startTime"
                }
            },
            messages: {
                endTime: {
                    compareTime: "结束时间必须大于开始时间"
                }
            }
        });

        // 自定义校验规则：结束时间必须大于开始时间
        $.validator.addMethod("compareTime", function(value, element, param) {
            var startTime = $("input[name='" + param + "']").val();
            var endTime = value;
            if (startTime == "" || endTime == "") {
                return true;
            }
            return new Date(endTime.replace(/-/g, "/")) > new Date(startTime.replace(/-/g, "/"));
        }, "结束时间必须大于开始时间");

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/edit", $('#form-meeting-edit').serialize());
            }
        }

        $("input[name='startTime']").datetimepicker({
            format: "yyyy-mm-dd HH:ii",
            // minView: "month",
            autoclose: true
        });

        $("input[name='endTime']").datetimepicker({
            format: "yyyy-mm-dd HH:ii",
            // minView: "month",
            autoclose: true
        });

        $(function() {
            var options = {
                data: [[${meeting.signInRecordList}]],
                pagination: false,
                showSearch: false,
                showRefresh: false,
                showToggle: false,
                showColumns: false,
                sidePagination: "client",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'index',
                    align: 'center',
                    title: "序号",
                    formatter: function (value, row, index) {
                    	var columnIndex = $.common.sprintf("<input type='hidden' name='index' value='%s'>", $.table.serialNumber(index));
                    	return columnIndex + $.table.serialNumber(index);
                    }
                },
                {
                    field: 'realname',
                    align: 'center',
                    title: '姓名',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='signInRecordList[%s].realname' value='%s'>", index, value);
                        return html;
                    }
                },

                {
                    field: 'phone',
                    align: 'center',
                    title: '手机号',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='signInRecordList[%s].phone' value='%s'>", index, value);
                        return html;
                    }
                },

                {
                    field: 'post',
                    align: 'center',
                    title: '职务',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='signInRecordList[%s].post' value='%s'>", index, value);
                        return html;
                    }
                },

                {
                    field: 'attendFlag',
                    align: 'center',
                    title: '是否参加',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='signInRecordList[%s].attendFlag' value='%s'>", index, value);
                        return html;
                    }
                },

                {
                    field: 'leaveReason',
                    align: 'center',
                    title: '请假原因',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='signInRecordList[%s].leaveReason' value='%s'>", index, value);
                        return html;
                    }
                },

                {
                    field: 'createBy',
                    align: 'center',
                    title: '创建者',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='signInRecordList[%s].createBy' value='%s'>", index, value);
                        return html;
                    }
                },

                {
                    field: 'createTime',
                    align: 'center',
                    title: '创建时间',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='signInRecordList[%s].createTime' value='%s'>", index, value);
                        return html;
                    }
                },

                {
                    field: 'updateBy',
                    align: 'center',
                    title: '更新者',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='signInRecordList[%s].updateBy' value='%s'>", index, value);
                        return html;
                    }
                },

                {
                    field: 'updateTime',
                    align: 'center',
                    title: '更新时间',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='signInRecordList[%s].updateTime' value='%s'>", index, value);
                        return html;
                    }
                },

                {
                    field: 'remark',
                    align: 'center',
                    title: '备注',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='signInRecordList[%s].remark' value='%s'>", index, value);
                        return html;
                    }
                },

                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var value = $.common.isNotEmpty(row.index) ? row.index : $.table.serialNumber(index);
                        return '<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="sub.delRowByIndex(\'' + value + '\')"><i class="fa fa-remove"></i>删除</a>';
                    }
                }]
            };
            $.table.init(options);
        });

        function addRow() {
            var count = $("#" + table.options.id).bootstrapTable('getData').length;
            var row = {
                index: $.table.serialNumber(count),
                realname: "",
                phone: "",
                post: "",
                attendFlag: "",
                leaveReason: "",
                createBy: "",
                createTime: "",
                updateBy: "",
                updateTime: "",
                remark: "",
            }
            sub.addRow(row);
        }
    </script>
</body>
</html>